home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Libraries / stdwin / Appls / test / hello.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-06-04  |  902 b   |  53 lines  |  [TEXT/????]

  1. /* The "Hello, world" koan according to David Rosenthal,
  2.    recoded for STDWIN.
  3.    Requirements: print "Hello, world" centered in a window,
  4.    recented after window resizes, redraw after window exposures.
  5.    Check error returns. */
  6.  
  7. #include "stdwin.h"
  8.  
  9. char *string= "Hello, world";
  10.  
  11. int text_h, text_v;
  12.  
  13. void
  14. placetext(win)
  15.     WINDOW *win;
  16. {
  17.     int width, height;
  18.     wgetwinsize(win, &width, &height);
  19.     text_v= (height - wlineheight()) / 2;
  20.     text_h= (width - wtextwidth(string, -1)) / 2;
  21. }
  22.  
  23. void
  24. drawproc(win, left, top, right, bottom)
  25.     WINDOW *win;
  26. {
  27.     wdrawtext(text_h, text_v, string, -1);
  28. }
  29.  
  30. main(argc, argv)
  31.     int argc;
  32.     char **argv;
  33. {
  34.     WINDOW *win;
  35.     winitargs(&argc, &argv);
  36.     win= wopen("Hello", drawproc);
  37.     
  38.     if (win != 0) {
  39.         placetext(win);
  40.         for (;;) {
  41.             EVENT e;
  42.             wgetevent(&e);
  43.             if (e.type == WE_CLOSE)
  44.                 break;
  45.             if (e.type == WE_SIZE)
  46.                 placetext(win);
  47.         }
  48.     }
  49.     
  50.     wdone();
  51.     exit(0);
  52. }
  53.